// pages/alarm_history/alarm_history.js
var app = getApp()
var page = 0
var page_size = 7
var header = {}

var GetList = function (that) {
  that.setData({
    hidden: false
  });
  wx.request({
    // url: 'https://119.3.46.145/server/GetAlarmHistory?userid=' + app.globalData.userid + '&start=' + page_size * page + '&num=' + page_size,
    // url: app.globalData.url+'GetUnHandleBranchAlarmList',
    url:app.globalData.url+'GetWXBranchAlarmList',
    data:{
      userid:app.globalData.userid,
      start:page_size * page,
      size:page_size
      // high:true,
      // low:true
    },    
    method: 'post',
    header: header,
    success: function (res) {
      //console.log(res, "res")
      let data = res.data.data;
      if (data.length == 0) {
        wx.showLoading({
          title: '没有更多了',
        })
        
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
        
        that.setData({
          hidden: true
        });
        return;
      }
      var tmp_list = that.data.list;
      for (var i = 0; i < data.length; i++) {
        tmp_list.push(data[i]);
      }
      that.setData({
        list: tmp_list
      });
      page++;
      that.setData({
        hidden: true
      });
      wx.hideLoading()
    }
  });
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hidden: true,
    list: [],
    scrollTop: 0,
    scrollHeight: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {   
    header = {
      'content-type': 'application/x-www-form-urlencoded',
      'cookie': "openid=" + app.globalData.openid
    }

    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.info(res.windowHeight);
        that.setData({
          scrollHeight: res.windowHeight
        });
      }
    });
  },

  bindDownLoad: function () {   
    var that = this;
    GetList(that);
  },

  scroll: function (event) {
    this.setData({
      scrollTop: event.detail.scrollTop
    });
  },

  refresh: function (event) {
    page = 0;
    this.setData({
      list: [],
      scrollTop: 0
    });
    //GetList(this)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    GetList(that);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that  = this
    //console.log("上拉加载更多");
    wx.showLoading({
      title: '正在加载',
    })
    GetList(that);

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})